import axios from 'axios'
// import router from '../router'
// import Vue from 'vue'

const axiosInstance = axios.create({
  // baseURL: 'http://192.168.16.123:8090',
  baseURL: 'http://torchex.global:8090/shop',
  responseType: 'json',
  timeout: 50000
})
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'

export function post (url, reqData) {
  return new Promise((resolve, reject) => {
    axiosInstance({
      method: 'post',
      url,
      data: reqData,
      responseType: 'json'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}
export function postHeader (url, reqData) {
  return new Promise((resolve, reject) => {
    axiosInstance({
      method: 'post',
      url,
      headers: {
        'X-Auth-Token': localStorage.getItem('X-Auth-Token')
      },
      data: reqData,
      responseType: 'json'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}
